local ReviveView = MClass("ReviveView")

function ReviveView:ctor()
    --self.root 默认为根节点
    UIHandler:addPopupUi(self.root, "ReviveView" )
    self.root:setPosition( cc.p( display.width/2, 0 ) )

    --Button
    self.mCancelReviveBtn = self.root:findChild("//Button_quxiao")
    assert(self.mCancelReviveBtn)

    self.mReviveBtn = self.root:findChild("//Button_queding")
    assert(self.mReviveBtn)

    self.mReviveNum = self.root:findChild("//Panel_tips/num")
    assert(self.mReviveNum)

    --设置事件
    self:init()
end

function ReviveView:init()
    self:setVisible(false)
    self.mCancelReviveBtn:setVisible(false)

    BattleUIEvent:addEventListener(BattleUIEvent.TYPE.BATTLE_SHOW_PVP_REVIVE,handler(self,ReviveView.showRevive))

    self:setSetup()
end

function ReviveView:showRevive(event)
    local reviveSelfTimes = event.reviveSelfTimes
    if reviveSelfTimes > 0 then
        -- todo
        self:setVisible(true)

        --显示次数
        self.mReviveNum:setString(reviveSelfTimes)
    else
        self:setVisible(false)
    end

end

function ReviveView:setSetup()
    --复活
    local function touchEvent_Revive(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            --print("=========touchEvent_Revive====BattleUIEvent.TYPE.BATTLE_REVIVE===============")
            BattleUIEvent:dispatchEvent(BattleUIEvent.TYPE.BATTLE_REVIVE)
        end
    end
    self.mReviveBtn:addTouchEventListener(touchEvent_Revive)
end



return ReviveView
